<?php

namespace cms\modules\v1\controllers;

use cms\modules\v1\models\access\ModuleActions;
use cms\modules\v1\models\system\OperationLog;
use common\models\Functions;
use yii\helpers\ArrayHelper;
use yii\filters\auth\HttpHeaderAuth;
use Yii;
/**
 * Default controller for the `v1` module
 */
class SystemController extends DefaultController
{

    public $modelClass = '';

    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            'authenticator' => [
                'class' =>  HttpHeaderAuth::className(),    //head头部验证
                'header' => 'access-token',
                'optional' => [                     //需要过滤掉不用token参数的方法
                    'operate-log',
                ]
            ]
        ]);
    }
    /**
     * Renders the index view for the module
     * @return string
     */
    public function init()
    {
        parent::init(); // TODO: Change the autogenerated stub
    }

    /**
     * 获取操作日志
     * @param int $page
     * @param int $size
     *
     * @return array
     */
    public function actionOperateLog($page = 1, $size = 50) {
        $check = (new ModuleActions())->checkActions();
        if ($check !== true) {
            return Functions::formatRestAPI(1, $check);
        }
        if (Yii::$app->request->isGet) {
            return (new OperationLog())->getList($page, $size);
        }
    }
}
